#include "Bullet.h"
#include "STGEngine.h"

#include <tolua++.h>
#include <lua.hpp>
#include <lualib.h>
#include <lauxlib.h>

#include "Defs.h"
#include <OgreLogManager.h>
using namespace Ogre;
CBullet::CBullet()
: mParent(NULL)
, mOwnDimensions(false)
, mWidth(100)
, mHeight(100)
, rotation(0)
, position(Vector3::ZERO)
, direction(Vector3::ZERO)
, colour(1.0f, 1.0f, 1.0f, 1.0f)
, timeToLive(10)
, totalTimeToLive(10)
, particleType(Visual)
, rotationSpeed(0)
, mAffectorName()
{

}

void CBullet::update(float timeElapsed) {
    static lua_State* L = static_cast<CSTGEngine*>(CSTGEngine::getSingletonPtr())->lua();
    if (mAffectorName.size() == 0) {
        position += (direction * timeElapsed);
    }
    else {
        lua_getglobal(L, mAffectorName.c_str());
        lua_pushnumber(L, timeElapsed);
        tolua_pushusertype(L, this, "CBullet");
        if (lua_pcall(L, 2, 0, 0)) {
            LUALOG(L);
            //lua_error(L);
        }
    }   
}
